/**
 *     This file is part of cesm-ws.
 *
 *     cesm-ws, Web Service for Community Earth System Model
 *
 *     Copyright (c) 2010, Purdue University and/or affilicates or thrid-party contributors as
 *     indicated by the @author tags or express copyright attribution statements
 *     applied by the authors. All third-party contributions are distributed under
 *     license by Purdue University.
 *
 *     cesm-ws is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with this distribution.  If not, see <http://www.gnu.org/licenses/>.
 */

package edu.purdue.rcac.grid.submit;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

import javax.activation.DataHandler;

import edu.purdue.rcac.grid.submit.globus.Translator;
import edu.purdue.rcac.grid.util.ByteArrayDataSource;

/**
 * {@link ServiceDispatcher} talks to this interface in order to: <br>
 * submit job <br>
 * get file content <br>
 * 
 * @author Han Zhang
 * 
 */
public interface Submitter extends Translator {
	/**
	 * Returns occurred error in a string
	 * 
	 * @return string that contains occurred error
	 */
	public String getError();

	/**
	 * Returns message that submitter formats
	 * 
	 * @return message
	 */
	public String getMessage();

	/**
	 * Returns job description
	 * 
	 * @return job description in specific dialect
	 */
	public String getJobDescription();

	/**
	 * Submit a job. You can get result by {@link #getResult()}
	 * 
	 * @throws SubmissionException
	 */
	public void submit() throws SubmissionException;

	/**
	 * Returns submission result as {@link ServiceResponse} object. Must be
	 * called after {@link #submit()}
	 * 
	 * @return submission result
	 */
	public SubmitterResponse getResult();

	/**
	 * Sets argument map. Must be called before {@link #submit()} if non-arg
	 * constructor is used to load {@link Submitter} instance.
	 * 
	 * @param argsMap
	 */
	public void setArgsMap(Map<String, String> argsMap);

	public InputStream getInputStream(String fromPath, String serverName,
			int serverPort) throws IOException;

	public OutputStream getOutputStream(String toPath, String serverName,
			int serverPort, boolean append) throws IOException;

	public SubmitterResponse write(DataHandler data, String toPath,
			boolean pathIsRelative) throws IOException;

	public ByteArrayDataSource readAsByteArray(String fromPath,
			boolean pathIsRelative) throws IOException;

	public String readAsString() throws IOException;
}
